<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class Role extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'role_name' => 'required|regex:/^[A-Za-z0-9\x{4e00}-\x{9fa5}]+$/u|between:2,20',
            'role_intro' => 'required|min:4',
            'role_sort' => 'integer',
        ];
    }

    public function messages(): array
    {
        return [
            'role_name.required' => '角色名称必须输入',
            'role_name.regex' => '角色名称不能输入非法字符',
            'role_name.between' => '角色名称长度只能是2至20个字符',

            'role_intro.required' => '角色介绍必须输入',
            'role_intro.min' => '角色介绍至少4个字符',

            'role_sort.integer' => '排序值只能是整数',
        ];
    }
}
